// @Software: serve
// @File : sys_dictionary
// @Author : vince
// @Time : 2021/9/25 7:07
// @Description  请填写文件描述
package fake

import (
	"gintify/core"
	"gintify/model"
	"gorm.io/gorm"
)

func FakeDictionary() {
	db := core.DB
	//dicts := &model.SysDictionary{Name: "Administrator", ParentId: 0, Description: "超级管理员角色，自动生成"}
	_ = db.Transaction(func(tx *gorm.DB) error {
		if tx.First(&model.SysDictionary{}).RowsAffected > 0 {
			core.LG.Errorf("SysDictionary表不为空")
			return nil
		}
		var menus []*model.SysMenu
		if err := tx.Model(&model.SysMenu{}).Find(&menus).Error; err != nil {
			core.LG.Errorf("获取SysDictionary列表失败, %v\n", err)
			return err
		}
		//TODO 由于闭包存在，dicts不能放在全局变量
		var dicts = []model.SysDictionary{
			{Name: "gender", Title: "性别", Description: "性别字典，自动生成", Words: []model.SysWord{
				{Value: 0, Label: "female", Text: "女"},
				{Value: 1, Label: "male", Text: "男"},
			}},
			{Name: "month", Title: "月份", Description: "月份字典，自动生成", Words: []model.SysWord{
				{Value: 1, Label: "January", Text: "一月", Short: "Jan"},
				{Value: 2, Label: "February", Text: "二月", Short: "Feb"},
				{Value: 3, Label: "March", Text: "三月", Short: "Mar"},
				{Value: 4, Label: "April", Text: "四月", Short: "Ari"},
				{Value: 5, Label: "May", Text: "五月", Short: "May"},
				{Value: 6, Label: "June", Text: "六月", Short: "Jun"},
				{Value: 7, Label: "July", Text: "七月", Short: "Jul"},
				{Value: 8, Label: "August", Text: "八月", Short: "Aut"},
				{Value: 9, Label: "September", Text: "九月", Short: "Sep"},
				{Value: 10, Label: "October", Text: "十月", Short: "Oct"},
				{Value: 11, Label: "November", Text: "十一月", Short: "Nov"},
				{Value: 12, Label: "December", Text: "十二月", Short: "Dec"},
			}},
			{Name: "week", Title: "星期", Description: "星期字典，自动生成", Words: []model.SysWord{
				{Value: 0, Label: "Sunday", Text: "星期天", Short: "Sun"},
				{Value: 1, Label: "Monday", Text: "星期一", Short: "Mon"},
				{Value: 2, Label: "Tuesday", Text: "星期二", Short: "Tue"},
				{Value: 3, Label: "Wednesday", Text: "星期三", Short: "Wed"},
				{Value: 4, Label: "Thursday", Text: "星期四", Short: "Thur"},
				{Value: 5, Label: "Friday", Text: "星期五", Short: "Fri"},
				{Value: 6, Label: "Saturday", Text: "星期六", Short: "Sat"},
			}},
		}

		if err := tx.Model(&model.SysDictionary{}).Create(&dicts).Error; err != nil {
			core.LG.Errorf("创建SysDictionary失败, %v\n", err)
			return err
		}

		return nil
	})
}
